<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Minimize sidelobe level of an array with arbitrary 2-D geometry</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/antenna_array_design/html/ant_array_min_sidelobe.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Minimize sidelobe level of an array with arbitrary 2-D geometry</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% "Convex optimization examples" lecture notes (EE364) by S. Boyd</span>
<span class="comment">% "Antenna array pattern synthesis via convex optimization"</span>
<span class="comment">% by H. Lebret and S. Boyd</span>
<span class="comment">% (figures are generated)</span>
<span class="comment">%</span>
<span class="comment">% Designs an antenna array such that:</span>
<span class="comment">% - it minimizes sidelobe level outside the beamwidth of the pattern</span>
<span class="comment">% - it has a unit sensitivity at some target direction</span>
<span class="comment">% - it has nulls (zero sensitivity) at specified direction(s) (optional)</span>
<span class="comment">%</span>
<span class="comment">% This is a convex problem (after sampling it can be formulated as an SOCP).</span>
<span class="comment">%</span>
<span class="comment">%   minimize   max |y(theta)|     for theta outside the beam</span>
<span class="comment">%       s.t.   y(theta_tar) = 1</span>
<span class="comment">%              y(theta_null) = 0  (optional)</span>
<span class="comment">%</span>
<span class="comment">% where y is the antenna array gain pattern (complex function) and</span>
<span class="comment">% variables are w (antenna array weights or shading coefficients).</span>
<span class="comment">% Gain pattern is a linear function of w: y(theta) = w'*a(theta)</span>
<span class="comment">% for some a(theta) describing antenna array configuration and specs.</span>
<span class="comment">%</span>
<span class="comment">% Written for CVX by Almir Mutapcic 02/02/06</span>

<span class="comment">% select array geometry</span>
ARRAY_GEOMETRY = <span class="string">'2D_RANDOM'</span>;
<span class="comment">% ARRAY_GEOMETRY = '1D_UNIFORM_LINE';</span>
<span class="comment">% ARRAY_GEOMETRY = '2D_UNIFORM_LATTICE';</span>

<span class="comment">% select if the optimal array pattern should enforce nulls or not</span>
HAS_NULLS = 0; <span class="comment">% HAS_NULLS = 1;</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% problem specs</span>
<span class="comment">%********************************************************************</span>
lambda = 1;           <span class="comment">% wavelength</span>
theta_tar = 60;       <span class="comment">% target direction (should be an integer -- discretization)</span>
half_beamwidth = 10;  <span class="comment">% half beamwidth around the target direction</span>

<span class="comment">% angles where we want nulls (optional)</span>
<span class="keyword">if</span> HAS_NULLS
  theta_nulls = [95 110 120 140 225];
<span class="keyword">end</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% random array of n antenna elements</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">if</span> strcmp( ARRAY_GEOMETRY, <span class="string">'2D_RANDOM'</span> )
  <span class="comment">% set random seed to repeat experiments</span>
  rand(<span class="string">'state'</span>,0);

  <span class="comment">% (uniformly distributed on [0,L]-by-[0,L] square)</span>
  n = 40;
  L = 5;
  loc = L*rand(n,2);
  angleRange = 360;

<span class="comment">%********************************************************************</span>
<span class="comment">% uniform 1D array with n elements with inter-element spacing d</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">elseif</span> strcmp( ARRAY_GEOMETRY, <span class="string">'1D_UNIFORM_LINE'</span> )
  <span class="comment">% (unifrom array on a line)</span>
  n = 30;
  d = 0.45*lambda;
  loc = [d*[0:n-1]' zeros(n,1)];
  angleRange = 180;

<span class="comment">%********************************************************************</span>
<span class="comment">% uniform 2D array with m-by-m element with d spacing</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">elseif</span> strcmp( ARRAY_GEOMETRY, <span class="string">'2D_UNIFORM_LATTICE'</span> )
  m = 6; n = m^2;
  d = 0.45*lambda;

  loc = zeros(n,2);
  <span class="keyword">for</span> x = 0:m-1
    <span class="keyword">for</span> y = 0:m-1
      loc(m*y+x+1,:) = [x y];
    <span class="keyword">end</span>
  <span class="keyword">end</span>
  loc = loc*d;
  angleRange = 360;

<span class="keyword">else</span>
  error(<span class="string">'Undefined array geometry'</span>)
<span class="keyword">end</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% construct optimization data</span>
<span class="comment">%********************************************************************</span>
<span class="comment">% build matrix A that relates w and y(theta), ie, y = A*w</span>
theta = [1:angleRange]';
A = kron(cos(pi*theta/180), loc(:,1)') + kron(sin(pi*theta/180), loc(:,2)');
A = exp(2*pi*i/lambda*A);

<span class="comment">% target constraint matrix</span>
[diff_closest, ind_closest] = min( abs(theta - theta_tar) );
Atar = A(ind_closest,:);

<span class="comment">% nulls constraint matrix</span>
<span class="keyword">if</span> HAS_NULLS
  Anull = []; ind_nulls = [];
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    [diff_closest, ind_closest] = min( abs(theta - theta_nulls(k)) );
    Anull = [Anull; A(ind_closest,:)];
    ind_nulls = [ind_nulls ind_closest];
  <span class="keyword">end</span>
<span class="keyword">end</span>

<span class="comment">% stopband constraint matrix</span>
ind = find(theta &lt;= (theta_tar-half_beamwidth) | <span class="keyword">...</span>
           theta &gt;= (theta_tar+half_beamwidth) );
<span class="keyword">if</span> HAS_NULLS, ind = setdiff(ind,ind_nulls); <span class="keyword">end</span>;
As = A(ind,:);

<span class="comment">%********************************************************************</span>
<span class="comment">% optimization problem</span>
<span class="comment">%********************************************************************</span>
cvx_begin
  variable <span class="string">w(n)</span> <span class="string">complex</span>
  minimize( max( abs(As*w) ) )
  subject <span class="string">to</span>
    Atar*w == 1;   <span class="comment">% target constraint</span>
    <span class="keyword">if</span> HAS_NULLS   <span class="comment">% nulls constraints</span>
      Anull*w == 0;
    <span class="keyword">end</span>
cvx_end

<span class="comment">% check if problem was successfully solved</span>
disp([<span class="string">'Problem is '</span> cvx_status])
<span class="keyword">if</span> ~strfind(cvx_status,<span class="string">'Solved'</span>)
  <span class="keyword">return</span>
<span class="keyword">end</span>

min_sidelobe_level = 20*log10( max(abs(As*w)) );
fprintf(1,<span class="string">'The minimum sidelobe level is %3.2f dB.\n\n'</span>,<span class="keyword">...</span>
          min_sidelobe_level );

<span class="comment">%********************************************************************</span>
<span class="comment">% plots</span>
<span class="comment">%********************************************************************</span>
figure(1), clf
plot(loc(:,1),loc(:,2),<span class="string">'o'</span>)
title(<span class="string">'Antenna locations'</span>)

<span class="comment">% plot array pattern</span>
<span class="keyword">if</span> angleRange == 180,
    theta = [1:360]';
    A = [ A; -A ];
<span class="keyword">end</span>
y = A*w;
figure(2), clf
ymin = floor(0.1*min_sidelobe_level)*10-10; ymax = 0;
plot([1:360], 20*log10(abs(y)), <span class="keyword">...</span>
     [theta_tar theta_tar],[ymin ymax],<span class="string">'r--'</span>,<span class="keyword">...</span>
     [theta_tar+half_beamwidth theta_tar+half_beamwidth],[ymin ymax],<span class="string">'g--'</span>,<span class="keyword">...</span>
     [theta_tar-half_beamwidth theta_tar-half_beamwidth],[ymin ymax],<span class="string">'g--'</span>);
<span class="keyword">if</span> HAS_NULLS <span class="comment">% add lines that represent null positions</span>
  hold <span class="string">on</span>;
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    plot([theta_nulls(k) theta_nulls(k)],[ymin ymax],<span class="string">'m--'</span>);
  <span class="keyword">end</span>
  hold <span class="string">off</span>;
<span class="keyword">end</span>
xlabel(<span class="string">'look angle'</span>), ylabel(<span class="string">'mag y(theta) in dB'</span>);
axis([0 360 ymin ymax]);

<span class="comment">% polar plot</span>
figure(3), clf
zerodB = -ymin;
dBY = 20*log10(abs(y)) + zerodB;
ind = find( dBY &lt;= 0 ); dBY(ind) = 0;
plot(dBY.*cos(pi*theta/180), dBY.*sin(pi*theta/180), <span class="string">'-'</span>);
axis([-zerodB zerodB -zerodB zerodB]), axis(<span class="string">'off'</span>), axis(<span class="string">'square'</span>)
hold <span class="string">on</span>
plot(zerodB*cos(pi*theta/180),zerodB*sin(pi*theta/180),<span class="string">'k:'</span>) <span class="comment">% 0 dB</span>
plot( (min_sidelobe_level + zerodB)*cos(pi*theta/180), <span class="keyword">...</span>
      (min_sidelobe_level + zerodB)*sin(pi*theta/180),<span class="string">'k:'</span>)  <span class="comment">% min level</span>
text(-zerodB,0,<span class="string">'0 dB'</span>)
tt = text(-(min_sidelobe_level + zerodB),0,sprintf(<span class="string">'%0.1f dB'</span>,min_sidelobe_level));
set(tt,<span class="string">'HorizontalAlignment'</span>,<span class="string">'right'</span>);
theta_1 = theta_tar+half_beamwidth;
theta_2 = theta_tar-half_beamwidth;
plot([0 55*cos(theta_tar*pi/180)], [0 55*sin(theta_tar*pi/180)], <span class="string">'k:'</span>)
plot([0 55*cos(theta_1*pi/180)], [0 55*sin(theta_1*pi/180)], <span class="string">'k:'</span>)
plot([0 55*cos(theta_2*pi/180)], [0 55*sin(theta_2*pi/180)], <span class="string">'k:'</span>)
<span class="keyword">if</span> HAS_NULLS <span class="comment">% add lines that represent null positions</span>
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    plot([0 55*cos(theta_nulls(k)*pi/180)], <span class="keyword">...</span>
         [0 55*sin(theta_nulls(k)*pi/180)], <span class="string">'k:'</span>)
  <span class="keyword">end</span>
<span class="keyword">end</span>
hold <span class="string">off</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling SDPT3 4.0: 1366 variables, 422 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 422
 dim. of socp   var  = 1023,   num. of socp blk  = 341
 dim. of linear var  = 341
 dim. of free   var  =  2 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|4.4e+02|2.1e+02|2.4e+05|-2.746283e-10  0.000000e+00| 0:0:00| chol  1  1 
 1|0.988|0.993|5.1e+00|1.7e+00|2.8e+03|-5.910542e-04 -3.754743e+01| 0:0:00| chol  1  1 
 2|0.996|1.000|1.8e-02|3.0e-02|4.3e+01|-1.073909e-04 -3.294803e+01| 0:0:00| chol  1  1 
 3|1.000|0.981|2.6e-06|7.1e-03|2.8e+00|-1.796667e-04 -2.767530e+00| 0:0:00| chol  1  1 
 4|1.000|0.889|6.0e-06|1.1e-03|6.9e-01|-3.329714e-03 -6.951011e-01| 0:0:00| chol  2  2 
 5|1.000|0.330|2.8e-06|7.2e-04|4.8e-01|-5.429142e-03 -4.885741e-01| 0:0:00| chol  2  2 
 6|1.000|0.198|3.0e-06|5.8e-04|4.0e-01|-9.246834e-03 -4.104551e-01| 0:0:00| chol  2  2 
 7|1.000|0.482|4.2e-07|3.0e-04|2.4e-01|-1.445316e-02 -2.511023e-01| 0:0:00| chol  2  2 
 8|0.886|0.301|2.3e-07|2.1e-04|1.7e-01|-2.381280e-02 -1.966527e-01| 0:0:00| chol  2  2 
 9|0.786|0.273|1.2e-07|1.5e-04|1.3e-01|-3.394623e-02 -1.629319e-01| 0:0:00| chol  2  2 
10|0.880|0.310|8.1e-08|1.1e-04|8.9e-02|-4.555463e-02 -1.348747e-01| 0:0:00| chol  2  2 
11|0.865|0.832|1.7e-08|3.2e-05|2.5e-02|-5.529791e-02 -8.055941e-02| 0:0:00| chol  2  2 
12|0.709|0.931|5.5e-09|7.8e-06|1.0e-02|-6.356684e-02 -7.375479e-02| 0:0:01| chol  2  2 
13|0.667|0.933|1.9e-09|3.1e-06|4.2e-03|-6.697721e-02 -7.115268e-02| 0:0:01| chol  2  2 
14|0.824|0.941|6.2e-10|1.3e-06|1.3e-03|-6.924831e-02 -7.050783e-02| 0:0:01| chol  3  2 
15|0.846|0.816|3.9e-10|3.8e-07|3.8e-04|-6.998889e-02 -7.036805e-02| 0:0:01| chol  2  3 
16|0.844|0.908|3.0e-10|1.1e-07|1.3e-04|-7.018828e-02 -7.032177e-02| 0:0:01| chol  3  3 
17|0.953|0.944|4.5e-10|4.0e-08|2.1e-05|-7.028437e-02 -7.030501e-02| 0:0:01| chol  3  3 
18|0.945|0.904|1.2e-09|6.3e-09|3.5e-06|-7.029930e-02 -7.030261e-02| 0:0:01| chol  4  5 
19|0.910|0.852|3.1e-09|1.1e-09|9.1e-07|-7.030149e-02 -7.030223e-02| 0:0:01| chol  5  6 
20|0.895|0.951|5.7e-09|3.6e-10|2.2e-07|-7.030245e-02 -7.030211e-02| 0:0:01| chol  6  9 
21|0.616|0.944|8.4e-09|3.2e-10|1.1e-07|-7.030248e-02 -7.030210e-02| 0:0:01| chol  8  9 
22|0.616|0.943|5.1e-09|4.7e-10|5.8e-08|-7.030245e-02 -7.030209e-02| 0:0:01| chol 20  9 
23|0.612|0.943|4.5e-09|7.0e-10|3.1e-08|-7.030240e-02 -7.030209e-02| 0:0:01| chol 18 23 
24|0.612|0.943|3.9e-09|9.4e-10|1.7e-08|-7.030231e-02 -7.030209e-02| 0:0:01|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 24
 primal objective value = -7.03023057e-02
 dual   objective value = -7.03020909e-02
 gap := trace(XZ)       = 1.66e-08
 relative gap           = 1.46e-08
 actual relative gap    = -1.88e-07
 rel. primal infeas (scaled problem)   = 3.87e-09
 rel. dual     "        "       "      = 9.40e-10
 rel. primal infeas (unscaled problem) = 0.00e+00
 rel. dual     "        "       "      = 0.00e+00
 norm(X), norm(y), norm(Z) = 5.6e-01, 1.1e+02, 1.5e+00
 norm(A), norm(b), norm(C) = 1.7e+02, 2.0e+00, 2.4e+00
 Total CPU time (secs)  = 1.07  
 CPU time per iteration = 0.04  
 termination code       =  0
 DIMACS: 3.9e-09  0.0e+00  1.1e-09  0.0e+00  -1.9e-07  1.5e-08
-------------------------------------------------------------------
 
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.0703021
 
Problem is Solved
The minimum sidelobe level is -23.06 dB.

</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="ant_array_min_sidelobe__01.png" alt=""> <img src="ant_array_min_sidelobe__02.png" alt=""> <img src="ant_array_min_sidelobe__03.png" alt=""> 
</div>
</div>
</body>
</html>